﻿using System.Text;
using RAP.Framework.Libary.Utils;
using RAP.Framework.Libary.DomTemplateBuilder.Element;
using RAP.Framework.Libary.DomTemplateBuilder.Interface;

namespace RAP.Framework.Libary.DomTemplateBuilder.Handler
{
	/// <summary>
	/// 数组动作Handler
	/// </summary>
	public class ArrayListActionHandler : PropertyElementHandler
    {
        public const string ARRAY_LIST_OBJECT = "ArrayListObject"; 

        public new ArrayListAction Element
        {
            get
            {
                return base.Element as ArrayListAction;
            }
            set
            {
                base.Element = value;
            }
        }

        public override void DoRender ( StringBuilder writer, object rootParamObject, object parentParamObject, ITemplateRenderContext context )
        {
            object paramObject = null;
			if ( !Property.IsNullOrEmpty ( ) )
            {
                paramObject = GetPropertyValue ( rootParamObject, parentParamObject, context );
            }
            else
            {
                paramObject = GetParamObject ( rootParamObject, parentParamObject, context );
            }
			var listTmp = context[ ARRAY_LIST_OBJECT ];
            context[ ARRAY_LIST_OBJECT ] = paramObject;
            DoRenderChildNodes ( writer, rootParamObject, parentParamObject, context );
			context[ ARRAY_LIST_OBJECT ] = listTmp;
        }

    }
}
